package grpc

import (
	"base_server/internal/models/cutpart"
	"base_server/internal/models/need_cutpart"
	"context"
	"jihe.common/protos/base_server/proto"
)

func (s *Server) BaseUpdateCutpartFabric(ctx context.Context, req *proto.BaseUpdateCutpartFabricReq) (ret *proto.BaseNull, err error) {
	ret = new(proto.BaseNull)
	cutpartTbl := cutpart.NewModel(s.Pgsql.Get())
	err = cutpartTbl.UpdateFabricIds(req)
	return
}

func (s *Server) BaseCreateNeedCutpart(ctx context.Context, req *proto.BaseNeedCutpart) (ret *proto.BaseNull, err error) {
	ret = new(proto.BaseNull)
	needCutpartTbl := need_cutpart.NewModel(s.Pgsql.Get())
	err = needCutpartTbl.Create(req)
	if err != nil {
		return
	}
	return
}

func (s *Server) BaseDeleteNeedCutpartByNeedId(ctx context.Context, req *proto.BaseNeedCutpart) (ret *proto.BaseNull, err error) {
	ret = new(proto.BaseNull)
	needCutpartTbl := need_cutpart.NewModel(s.Pgsql.Get())
	err = needCutpartTbl.DeleteByNeedId(req.NeedId)
	if err != nil {
		return
	}
	return
}

func (s *Server) BaseGetCutpartByNeedId(ctx context.Context, req *proto.BaseNeedCutpart) (ret *proto.BaseNeedCutparts, err error) {
	ret = new(proto.BaseNeedCutparts)
	needCutpartTbl := need_cutpart.NewModel(s.Pgsql.Get())
	ret.List, err = needCutpartTbl.GetListByNeedId(req.NeedId)
	if err != nil {
		return
	}
	return
}

func (s *Server) BaseGetCutpartsByIds(ctx context.Context, req *proto.BaseGetCutpartsByIdsReq) (ret *proto.BaseCutparts, err error) {
	ret = new(proto.BaseCutparts)
	cutpartTbl := cutpart.NewModel(s.Pgsql.Get())
	ret.BaseCutpartList, err = cutpartTbl.GetByIds(req.Ids)
	if err != nil {
		return
	}
	return
}

func (s *Server) BaseUpdateNeedCutpartByCutpartId(ctx context.Context, req *proto.BaseNeedCutpart) (ret *proto.BaseNull, err error) {
	ret = new(proto.BaseNull)
	needCutpartTbl := need_cutpart.NewModel(s.Pgsql.Get())
	err = needCutpartTbl.Update(req)
	return
}
